package com.company.server;

import com.company.common.User;

import java.util.HashMap;
import java.util.Map;

public class UserDao {
    private static final Map<String, String> USER_MAP = new HashMap<>();

    static {
        USER_MAP.put("1", "1");
        USER_MAP.put("2", "2");
        USER_MAP.put("3", "3");
    }

    public static boolean login(User user) {
        String pwd = USER_MAP.get(user.getName());
        return user != null && user.getPwd().equals(pwd);
    }

    public static boolean register(User user) {
        if (!USER_MAP.containsKey(user.getName())) {
            USER_MAP.put(user.getName(), user.getPwd());
            return true;
        }
        return false;
    }

    public static String[] getOnlineUsers() {
        return ConnCliThdManage.getKeys();
    }
}
